package org.example;

import java.io.IOException;

public class StartOtherProcess {
    public static void main(String[] args) throws IOException, InterruptedException {
        // 多个参数分别传，像这样
//        ProcessBuilder pb = new ProcessBuilder("python","d:\\python_test\\main.py", "1", "2");
        ProcessBuilder pb = new ProcessBuilder("java", "-version");
        pb.redirectErrorStream(true);
        Process process = pb.start();

        // 等待进程执行完，打印退出码
        int exitValue = process.waitFor();
        System.out.println(exitValue);

        // 获取进程输出信息
        byte[] bytes = new byte[process.getInputStream().available()];
        process.getInputStream().read(bytes);
        System.out.println(new String(bytes));
    }
}
